#include "CylinderParser.h"


CylinderParser::CylinderParser(void)
{
}


CylinderParser::~CylinderParser(void)
{
}

CylinderParser::CylinderParser(float base, float top, float height, int slices, int stacks, string tx_id ,string mat_id): PrimitiveParser(tx_id, mat_id)
{
	this->base = base;
	this->top = top;
	this->height = height;
	this->slices = slices;
	this->stacks = stacks;

	top_disk = top == 0.0 ? false : true;
	base_disk = base == 0.0 ? false : true;

	cyl_glQ = gluNewQuadric();
	gluQuadricOrientation(cyl_glQ, GLU_OUTSIDE);
	gluQuadricDrawStyle(cyl_glQ, GLU_FILL);
	gluQuadricTexture(cyl_glQ, GL_TRUE);
}

void CylinderParser::render(){
	if(texture_id != "none" && texture_id != "inherit")
		render(texture);
	else{
		//gluQuadricOrientation(cyl_glQ, GLU_OUTSIDE);
		gluCylinder(cyl_glQ,base,top,height,slices,stacks);

		if(base_disk){
			glPushMatrix();
			glRotatef(180,0,1,0);
			gluDisk(cyl_glQ,0.0,base,slices,stacks);
			glPopMatrix();
		}
		if(top_disk){
			glPushMatrix();
			glTranslatef(0.0,0.0,height);
			gluDisk(cyl_glQ,0.0,top,slices,stacks);
			glPopMatrix();
		}
	}
}

void CylinderParser::render(TextureParser* tx){
	glEnable(GL_TEXTURE_2D);
	//gluQuadricTexture(cyl_glQ, true);
	glBindTexture(GL_TEXTURE_2D, tx->tx_id);
	
	//gluQuadricOrientation(cyl_glQ, GLU_OUTSIDE);
	gluCylinder(cyl_glQ,base,top,height,slices,stacks);

	if(base_disk){
		glPushMatrix();
		glRotatef(180,0,1,0);
		gluDisk(cyl_glQ,0.0,base,slices,stacks);
		glPopMatrix();
	}
	if(top_disk){
		glPushMatrix();
		glTranslatef(0.0,0.0,height);
		gluDisk(cyl_glQ,0.0,top,slices,stacks);
		glPopMatrix();
	}

	glDisable(GL_TEXTURE_2D);
}